<template>
  <!-- 留言 -->
  <div>
    <!-- 头部区域 -->
    <div class="head">
      <el-descriptions :column="3" border>
        <el-descriptions-item>
          <template slot="label"> 我的毕业设计课题 </template>
          <router-link to="/mytopic">{{ topic }}</router-link>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 指导老师 </template>
          <router-link
            :to="{ path: '/teacherinfo', query: { id: teacher_id } }"
            >{{ teacher }}</router-link
          >
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <!-- 文本区域 -->
    <div class="content">
      <template>
        <el-table :data="tableData" style="width: 100%">
          <!-- <el-table-column prop="date" label="教师" width="180">
          </el-table-column> -->
          <el-table-column label="日期" width="600">
            <template slot-scope="scope">
              <span style="margin-left: 10px">{{
                scope.row.resMessage_date | formatData
              }}</span>
            </template>
          </el-table-column>
          <el-table-column label="留言详情" width="600">
            <template slot-scope="scope">
              <span style="margin-left: 10px">{{
                scope.row.resMessage_content
              }}</span>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
  </div>
</template>
<script>
export default {
  created() {
    this.getinfo();
    this.getmessage();
  },

  data() {
    return {
      topic: "",
      teacher: "",
      tableData: [],
      teacher_id: "",
    };
  },
  filters: {
    formatData(time) {
      return new Date(time).toLocaleString();
    },
  },
  methods: {
    getinfo() {
      this.$http.get("http://127.0.0.1:8080/my/getTopic").then((res) => {
        // console.log(res.data.data[1][0]);\
        if (res.data.status == 0) {
          this.topic = res.data.data[1][0].topic_name;
          this.teacher = res.data.data[0][0].teacher_name;
          this.teacher_id = res.data.data[0][0].id;
        } else {
          this.topic = "";
          this.teacher = "";
        }
      });
    },

    getmessage() {
      this.$http.get("http://127.0.0.1:8080/my/getmessage").then((res) => {
        // console.log(res.data.data);
        if (res.data.status == 0) {
          this.tableData = res.data.data;
          // console.log(this.tableData);
        } else {
          this.tableData = [];
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
.content {
  margin: 20px 0;
}
.content input {
  resize: none;
}
button {
  position: absolute;
  right: 50px;
}
</style>
